How to Loop to plot histogram and line plot?

4 views (last 30 days)
Hello I want to use loop to plot histogram and line plot. I am getting error
for i=4:8;k=1:2
subplot(1,2,k)
plot(Temp(:,3),Temp(:,i))
end
for p= 4:7
subplot(2,2,k)
histogram(Temp.[p])
end

The following is not clear and most probably your error:
for i=4:8;k=1:2
subplot(1,2,k)
plot(Temp(:,3),Temp(:i))
end
Are you trying to have 2 loops there? What your code is doing is the following:
for i=4:8
k=1:2
subplot(1,2,k)
plot(Temp(:,3),Temp(:i))
end
It runs a loop on i, then it assigns k a range between 1 and 2, then calls a subplot with the value of k, which prompts an error as you should have a single value.
Perhaps you need the following:
for i=4:8
for k=1:2
subplot(1,2,k)
plot(Temp(:,3),Temp(:i))
end
end
I have not tried to define any method, just to point out your error here:
plot(Temp(:,3),Temp(:i))
This will not work, it requires a comma between the : and the i like this
plot(Temp(:,3),Temp(:,i))

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.78176177,"math_prob":0.97961885,"size":1324,"snap":"2022-05-2022-21","text_gpt3_token_len":421,"char_repetition_ratio":0.14469697,"word_repetition_ratio":0.009708738,"special_character_ratio":0.326284,"punctuation_ratio":0.2,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99917126,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-22T05:47:50Z\",\"WARC-Record-ID\":\"<urn:uuid:2088ec3f-6b2e-4e87-b256-3033c1b620c6>\",\"Content-Length\":\"145620\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0593b653-d2ec-4c1d-9ed1-e1d3dd69b8f2>\",\"WARC-Concurrent-To\":\"<urn:uuid:c1d13e07-297e-404c-9295-674de578bf0f>\",\"WARC-IP-Address\":\"23.221.210.185\",\"WARC-Target-URI\":\"https://www.mathworks.com/matlabcentral/answers/847050-how-to-loop-to-plot-histogram-and-line-plot\",\"WARC-Payload-Digest\":\"sha1:Z34ZMUJ45ACICLDV72G7PF7YSASWPGTH\",\"WARC-Block-Digest\":\"sha1:5IXVL63FZ2IQMCKLOGE7QFYVHPRF25RS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320303747.41_warc_CC-MAIN-20220122043216-20220122073216-00122.warc.gz\"}"}