이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Help with unstack function on matlab
조회 수: 8 (최근 30일)
이전 댓글 표시
I'm unable to figure out a way to use the unstack function for my data set. The task for my data set was set up where a subject was prompted 3 times in a day and I want to separate the data from the dates column for each day. I've attached a sample example of what I want to look like and also the data set I actually want to work with. Also attached the code that I wrote to try to figure it out on my own.
i=[3:53];
Survey_Prompt_Unstack = unstack(Survey_Prompt, 3, i);
Each time I try to run the command above, I get this message:
%Error using tabular/unstack
%The indicator variable must be specified as a single variable.
채택된 답변
Star Strider
2022년 7월 7일
I am not certain what you want.
This is the best I can do with the provided data —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057225/Survey_Prompt.xlsx', 'VariableNamingRule','preserve')
Warning: Table variable names were truncated to the length namelengthmax. The original names are saved in the VariableDescriptions property.
T1 = 8×53 table
UserId SurveyName SurveyStartedDate SurveySubmittedDate RightNowHowMuchDoYouFeel_Sad RightNowHowMuchDoYouFeel_InAGoodMood RightNowHowMuchDoYouFeel_ConnectedWithOthers RightNowHowMuchDoYouFeel_PsychologicalEmotionalPain RightNowHowMuchDoYouFeel_Bored RightNowHowMuchDoYouFeel_LikeYouNeedToEscape RightNowHowMuchDoYouFeel_AgitatedIrritated RightNowHowMuchDoYouFeel_Worried RightNowHowMuchDoYouFeel_Anxious RightNowHowMuchDoYouFeel_Energetic RightNowHowMuchDoYouFeel_Selfhatred RightNowHowMuchDoYouFeel_Angry RightNowHowMuchDoYouFeel_OnEdge RightNowHowMuchDoYouFeel_Numb RightNowHowMuchDoYouFeel_Grateful RightNowHowMuchDoYouFeel_PhysicalPainOrDiscomfort RightNowHowMuchDoYouFeel_Hopeless RightNowHowMuchDoYouFeel_Lonely RightNowHowMuchDoYouFeel_Humiliated RightNowHowMuchDoYouFeel_DesireToAvoid RightNowHowMuchDoYouFeel_UrgeToUseAlcohol RightNowHowMuchDoYouFeel_UrgeToUseHeroinOrOpioids RightNowHowMuchDoYouFeel_UrgeToUseCocaine RightNowHowMuchDoYouFeel_UrgeToEatSomethingSweet RightNowHowMuchDoYouFeel_UrgeToEatSomethingSavory RightNowHowMuchDoYouFeel_UrgeToHurtYourself RightNowHowMuchDoYouFeel_UrgeToDie RightNowHowMuchDoYouFeel_UrgeToDoSomethingRiskyOrImpulsive RightNowHowMuchDoYouFeel_NeedToBeWithFriendsOrFamily RightNowIWouldBeAbleToEnjoyThingsThatIUsuallyLike InThePastHourDidAnyOfTheFollowingHappen_ISawHeroinOrOpioids InThePastHourDidAnyOfTheFollowingHappen_SomeoneOfferedMeHeroinO InThePastHourDidAnyOfTheFollowingHappen_OutOfTheBlueIFeltTempte InThePastHourDidAnyOfTheFollowingHappen_IHandled10DollarsOrMore InThePastHourDidAnyOfTheFollowingHappen_IWantedToSeeWhatWouldHa InThePastHourDidAnyOfTheFollowingHappen_IUsedHeroinOrOpioids HowManyBagsPillsDidYouUse InThePastHourDidYouUseAnyOfTheFollowing HowMuchMoneysWorthOfCocaineDidYouHave HowManyDrinksDidYouHave HowManyBenzodiazepineOrBenzosPills HowManyJointsDidYouHave WhatDidYouUse WhereAreYouRightNow RightBeforeYouStartedThisSurveyWhoWereYouWith ChooseBelowWhoYouWereWith_CheckAllThatApply HowCloseOrConnectedDoYouFeelWithThesePeopleRightNow HaveYouEverUseUsedDrugsWithAtLeastOneOfThesePeopleBefore RightBeforeYouStartedThisSurveyWhatWereYouDoing_CheckAllThatApp
_____________________ ___________________ _________________ ___________________ ____________________________ ____________________________________ ____________________________________________ ___________________________________________________ ______________________________ ____________________________________________ __________________________________________ ________________________________ ________________________________ __________________________________ ___________________________________ ______________________________ _______________________________ _____________________________ _________________________________ _________________________________________________ _________________________________ _______________________________ ___________________________________ ______________________________________ _________________________________________ _________________________________________________ _________________________________________ ________________________________________________ _________________________________________________ ___________________________________________ __________________________________ __________________________________________________________ ____________________________________________________ _________________________________________________ ___________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ ____________________________________________________________ _________________________ _______________________________________ _____________________________________ _______________________ __________________________________ _______________________ _____________________ ___________________ _____________________________________________ ___________________________________________ ___________________________________________________ ________________________________________________________ _______________________________________________________________
{'213hj123jl12132nm'} {'Question_Prompt'} 05-Aug-2020 05-Aug-2020 0 92 55 17 18 6 0 0 12 78 0 0 0 0 69 6 0 0 0 12 0 0 0 11 NaN 0 0 0 18 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Working (job or school work)' }
{'213hj123jl12132nm'} {'Question_Prompt'} 06-Aug-2020 06-Aug-2020 0 77 68 10 22 22 14 22 17 86 0 10 8 0 78 7 0 14 0 9 0 0 0 10 NaN 0 0 0 14 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Working (job or school work)' }
{'213hj123jl12132nm'} {'Question_Prompt'} 06-Aug-2020 06-Aug-2020 0 81 31 0 17 32 8 23 11 88 0 6 8 0 79 14 0 31 0 0 0 0 0 12 NaN 0 0 0 23 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Eating' }
{'213hj123jl12132nm'} {'Question_Prompt'} 07-Aug-2020 07-Aug-2020 0 76 30 4 8 23 0 6 0 81 0 0 0 0 80 5 0 13 0 0 0 0 0 0 NaN 0 0 0 0 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At work'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Working (job or school work)' }
{'213hj123jl12132nm'} {'Question_Prompt'} 07-Aug-2020 07-Aug-2020 0 81 21 6 7 21 8 9 12 79 0 0 0 0 77 6 0 12 0 0 0 0 0 3 NaN 0 0 0 17 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At work'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Working (job or school work)' }
{'213hj123jl12132nm'} {'Question_Prompt'} 07-Aug-2020 07-Aug-2020 14 51 21 43 47 52 50 66 50 40 0 46 56 57 54 70 52 53 53 62 2 0 0 51 NaN 0 0 0 55 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Eating' }
{'213hj123jl12132nm'} {'Question_Prompt'} 07-Aug-2020 07-Aug-2020 6 62 49 11 67 58 29 53 49 34 0 0 39 56 74 77 38 50 51 53 2 0 0 46 NaN 0 0 0 53 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Watching TV/listening to music/playing video games'}
{'213hj123jl12132nm'} {'Question_Prompt'} 08-Aug-2020 08-Aug-2020 2 84 75 2 48 5 0 48 8 52 0 0 0 0 63 75 2 25 23 14 0 0 0 21 NaN 0 0 0 32 NaN {'No'} {'No'} {'No'} {'No'} {'No'} {'No'} NaN {'None'} NaN NaN NaN NaN {'CONDITION_SKIPPED'} {'At home'} {'Alone'} {'Peer (not friend or acquaintance)'} {'CONDITION_SKIPPED'} NaN {'Watching TV/listening to music/playing video games'}
VN = T1.Properties.VariableNames;
T1e = T1(:,[1 3 4 5]); % Eliminate 'SurveyName' Variable
T1u = unstack(T1e,VN{3},VN{4})
Warning: Table variable names that were not valid MATLAB identifiers have been modified. Since table variable names must be unique, any table variable names that happened to match the new identifiers also have been modified.
To use the original INDVAR values as table variable names, set 'VariableNamingRule' to 'preserve'.
To use the original INDVAR values as table variable names, set 'VariableNamingRule' to 'preserve'.
T1u = 4×6 table
UserId RightNowHowMuchDoYouFeel_Sad x05_Aug_2020 x06_Aug_2020 x07_Aug_2020 x08_Aug_2020
_____________________ ____________________________ ____________ ____________ ____________ ____________
{'213hj123jl12132nm'} 0 05-Aug-2020 06-Aug-2020 07-Aug-2020 NaT
{'213hj123jl12132nm'} 14 NaT NaT 07-Aug-2020 NaT
{'213hj123jl12132nm'} 6 NaT NaT 07-Aug-2020 NaT
{'213hj123jl12132nm'} 2 NaT NaT NaT 08-Aug-2020
Experiment with this to get the result you want.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)